/*let data_0;
 function cb(res) {
 data_0=res;
 }
 getWeather("长春",cb);*/
var cityName = new Array(10);
let weatherData = new Array(10);
cityName[0] = "长春";
cityName[1] = "大连";
cityName[2] = "石家庄";
cityName[3] = "包头";
cityName[4] = "西宁";
cityName[5] = "南通";
cityName[6] = "广州";
cityName[7] = "南宁";
cityName[8] = "呼伦贝尔";
cityName[9] = "敦煌";
for (var i = 0; i < cityName.length; i++) {
  (function (i) {
    var item = cityName[i];
    setTimeout(function () {
      function cb(res) {
        weatherData[i] = res;
      }

      getCityWeather(cityName[i], cb);
    });
  }(i));
}

function getCityWeather(city, cb) {
  let result;
  let high;
  let low;
  let type;
  let fengxiang;
  let xmlhttp;
  if (window.XMLHttpRequest) {
    //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
    xmlhttp = new XMLHttpRequest();
  } else {
    // IE6, IE5 浏览器执行代码
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  //建立连接
  xmlhttp.open("GET", "http://wthrcdn.etouch.cn/weather_mini?city=" + city, true);
  //发送请求
  xmlhttp.send();
  //响应
  xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
      let obj = JSON.parse(xmlhttp.responseText);     //  将json数据转换成对象

      let smg = obj.data.forecast;
      high = smg[0].high;
      low = smg[0].low;
      type = smg[0].type;
      fengxiang = smg[0].fengxiang;
      let a = high.split(" ")[1];
      // result = type + " " + high + " " + low + " " + fengxiang;
      result = low.split(" ")[1] + " ~ " + high.split(" ")[1] + " " + type + " " + fengxiang;
      cb(result);
      //console.log(result)
    }
  };
}

